<?php
/**
 * CreateTime: 2022/5/30 16:03
 */

namespace App\ServiceChecker\Contract;

use App\Consts\BaseConsts\BaseConsts;
use App\Consts\ContractConsts\ContractStatusConsts;
use App\Consts\ResponseConsts\ResponseStatusConsts;
use App\Func\ResponseFunc;
use App\Models\NewContract\ContractModel;
use App\ServiceChecker\BasicServiceChecker;
use Illuminate\Http\Exceptions\HttpResponseException;

class ContractLegitimacy extends BasicServiceChecker
{
    private ContractModel $contractModel;

    public function __construct()
    {
        parent::__construct();
        $this->contractModel = new ContractModel();
    }

    public function verifyRecodeContractIsExists($contractId)
    {
        $recodeStatus = app()
            ->gcHelper
            ->getDictionaryInfoByDictionaryKey(ContractStatusConsts::CONTRACT_STATUS_RECORD,[
            'dictionary_value'
        ])['dictionary_value'];
        $isExist = $this->contractModel->isExistByCondition([
            'contract_id' => $contractId,
            'status' => BaseConsts::STATUS_NORMAL,
            'contract_status' => $recodeStatus
        ]);

        if(!$isExist){
            throw new HttpResponseException( ResponseFunc::returnJson(
                'error',
                null,
                '当前合同未归档或不存在',
                ResponseStatusConsts::OK_200_RESPONSE_STATUS,
            ));
        }
    }

}